<?php
namespace Common\Model;
use Think\Model;

class WechatResponseModel extends Model{

	/**
	 *  是否存在关键字
	 *  @param $keyword 关键字
	 *  @param $get 查找方法  find,select
	 */
	public function isKeyword($keyword,$get="find"){
		$where['keywords']=$keyword;
		$where['type']=0;
		$where['isOn']=1;
		
		$result=$this->where($where)->$get();   //***允许设置多个返回类型
		
		return $result;
	}
	
	/**
	 *  返回自动回复
	 */
	public function getAutoReply(){
		$where['type']=1;
		$where['isOn']=1;
	
		$result=$this->where($where)->find();   
	
		return $result;
	}
	
	/**
	 *  返回关注回复
	 */
	public function getFollowReply(){
		$where['type']=2;
		$where['isOn']=1;
		
		$result=$this->where($where)->find();   
	
		return $result;
	}
        
	/**
	 *  根据ID返回一条关键字回复
	 */
	public function getKeyReplyById($rspID){
		$where['responseID']=$rspID;
		$where['type']=0;
		$where['isOn']=1;
		
		$result=$this->where($where)->find();   
	
		return $result;
	}
        
        /**
         * 获得列表（带基本查询）
         */
        public function getKeyReplyList($pageNo = 1, $pageSize = 15, $where = array(), $order = array(),$field="*") {
            $rt = $this->field($field)->where($where)->page("$pageNo,$pageSize")->order($order)->select();
            return $rt;
        }

        public function getKeyReplyListLength($where = array()) {
            return $this->where($where)->count();
        }

	/**
	 *  更新自动回复
	 */
	public function updateAutoReply($data){
		return $this->save($data);
	}
}
?>